package com.houxr;

import com.houxiurong.entity.ConstructList;
import com.houxiurong.utils.HttpHelper;
import com.houxiurong.utils.JSONUtils;
import com.houxiurong.utils.MapValueUtil;
import org.junit.Test;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

/**
 * Created by houxiurong on 2017/6/13.
 */
public class MeTest {

    public static void main(String[] args) {
        for (int i = 0; i < 30; i++) {
            System.out.println(i + "random:" + ThreadLocalRandom.current().nextInt(1, 10));
        }
    }

    @Test
    public void fromJson2Entity() {
        String entUserId = "402882694fe131";
        String host = "http://101.64.238.234/info/";
        String url = String.format(host + "findConstructSituationByEntUserId?entUserId=%s", new Object[]{entUserId});
        try {
            String result = HttpHelper.httpsGet(url);
            System.out.println("获取json值:" + result);

            Map<String, Object> resultMap = HttpHelper.doGet(url);
            Integer code = MapValueUtil.getInteger(resultMap, "code");
            System.out.println("resultCode:" + code);
            String jsonData = JSONUtils.toString(MapValueUtil.getObject(resultMap, "data"));
            System.out.println("jsonData:" + jsonData);

            ConstructList crs = JSONUtils.parse(result, ConstructList.class);
            System.out.println("deka end MapEntity:" + JSONUtils.toString(crs));
            System.out.println("获取的数据值crs.getCode():" + crs.getCode());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
